module.exports = function ($scope, $stateParams, $state, $resource, saveCCBPay, findByBranchId, updateCCBPay) {
  $scope.obj = {}
  $scope.url = '';
  if ($stateParams.id) {
    $scope.url = updateCCBPay;
  } else {
    $scope.url = saveCCBPay;
    $scope.obj = {
      'merchant_id' : '',
      'pos_id' : '',
      'bank_url' : '',
      'branch_id' : '',
      'public_key' : '',
      'company_code' : ''
    }
  }
  $scope.getInfo = function() {
    findByBranchId.save({'id' : $stateParams.id}, function (res) {
			if (res.errcode !== 0) {
				alert(res.errmsg);
			}
			else {
        $scope.obj = res.data;
        console.log($scope.obj, '详情')
				// $state.go('app.menuPermissionList');
			}
		});
  }
  if ($stateParams.id) {
    $scope.getInfo();
  }
	$scope.gogo = function () {
		$scope.url.save($scope.obj, function (res) {
      if (res.errcode == 0) {
        if (res.data.errorCode == '11002') {
          alert(res.data.errorMsg);
        } else {
          alert('操作成功');
          $state.go('app.longPaySetting');
        }
			} else {
        alert(res.errmsg);
			}
    });
	};

};